Skip to content

๐Ÿ Python & Package Manager Cheat Sheet โ€‹

A quick-reference guide for Miniconda3 environment orchestration, lightning-fast package compilation via Astral's Rust-based uv, and Python environment diagnostic checks.


๐Ÿ—ƒ๏ธ Conda Environment Management โ€‹

๐Ÿ› ๏ธ Environment Creation & Clones โ€‹

bash
### Create a new environment with a specific Python version
conda create -n ai_dev python=3.11 -y

### Create a complete duplicate (clone) of an existing environment
conda create --name ai_dev_backup --clone ai_dev

### Create an environment directly from a configured YAML environment file
conda env create -f environment.yml

๐Ÿ“ก Lifecycle & System Audits โ€‹

bash
### List all active conda environments and their absolute system paths
conda env list
conda info --envs

### Activate an isolated environment
conda activate ai_dev

### Deactivate the current environment, returning to system base shell
conda deactivate

### Completely remove an environment from the system
conda env remove -n ai_dev

๐Ÿ“ค Environment Exports & Backups โ€‹

bash
### Export active environment parameters as a clean, portable YAML config
conda env export > environment.yml

### Export simple python requirements (cross-compatible with pip)
conda list --export > requirements-conda.txt

โšก uv (Astral Rust Package Manager) โ€‹

NOTE

Why uv? uv is a drop-in replacement for pip and pip-tools written in Rust. It resolves and installs packages in milliseconds by using aggressive global caching and content-addressable storage, bypassing slow python resolution backtracking.

๐Ÿ“ฆ Quick Installations โ€‹

bash
### Install a package inside the active conda environment using uv
uv pip install httpx pydantic

### Install a package with exact version locks
uv pip install fastapi==0.110.0

### Install packages recursively from a standard requirements file
uv pip install -r requirements.txt

๐Ÿ”’ Lockfile Compilations & Resolvers โ€‹

bash
### Compile a loosely defined requirements list into a locked requirements.txt
uv pip compile requirements.in -o requirements.txt

### Sync the active virtual environment to match the requirements.txt exactly
### (Warning: This will uninstall any local packages NOT listed in the lockfile)
uv pip sync requirements.txt

๐Ÿงน System Cache & Space Audits โ€‹

bash
### Show total disk space consumed by the global uv compiler cache
uv cache dir
uv cache info

### Completely purge the global cache (forces re-downloads on next install)
uv cache clean

### Purge specific cached packages
uv cache prune

๐Ÿ’ก Python Environment Diagnostic Checks โ€‹

Use these terminal commands to diagnose path pollution, active packages, and python import conflicts:

bash
### Verify absolute path of active python interpreter
python -c "import sys; print(sys.executable)"

### Print all active module lookup paths in execution order
python -c "import sys; print('\n'.join(sys.path))"

### Check active version of a specific package
python -c "import httpx; print(httpx.__version__)"
python -c "import pydantic; print(pydantic.__version__)"

### List all installed packages and their exact compiled versions
uv pip list
pip list